package sketch.generator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import sketch.generator.examples.SequentialValue;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class ExhaustiveTypedValueGeneratorTest extends TestCase {
	public static Test suite() {
        return new TestSuite(ExhaustiveTypedValueGeneratorTest.class);
    }
	
	public void testValueGenForInt() {
		List<Integer> list = new ArrayList<Integer>();
		list.add(1);
		list.add(2);
		list.add(3);
		list.add(4);
		ExhaustiveTypedValueGenerator<Integer> innerGen = new ExhaustiveTypedValueGenerator<Integer>(new Class<?>[]{int.class, int.class}, list);
		int count = 0;
		while(innerGen.hasNext()) {
			System.out.println(innerGen.next().getValues());
			count++;
		}
		assertTrue("The count is: " + count, count == 16);
	}
	
	public void testValueGenWithTypes() {
		ExhaustiveTypedValueGenerator<Object> generator = new ExhaustiveTypedValueGenerator<Object>(
				new Class<?>[]{int.class, String.class, List.class}, 23, "hello", new LinkedList(), "world", 44, 66
		);
		int count = 0;
		while(generator.hasNext()) {
			SequentialValue<Object> value = generator.next();
			System.out.println(value);
			count ++;
		}
		assertTrue("the count is: " + count, count == 3*2*1);
	}
	
	public void testValueGenWithTypesWithNull() {
		ExhaustiveTypedValueGenerator<Object> generator = new ExhaustiveTypedValueGenerator<Object>(
				new Class<?>[]{int.class, String.class, List.class}, 23, "hello", new LinkedList(), "world", 44, 66, null
		);
		int count = 0;
		while(generator.hasNext()) {
			SequentialValue<Object> value = generator.next();
			System.out.println(value);
			count ++;
		}
		assertTrue("the count is: " + count, count == 3*3*2);
	}
	
	public void testValueGenWithTypesWithSubclass() {
		LinkedList linkedList = new LinkedList();
		linkedList.add("linked list");
		ExhaustiveTypedValueGenerator<Object> generator = new ExhaustiveTypedValueGenerator<Object>(
				new Class<?>[]{int.class, String.class, List.class}, 23, "hello", linkedList,
				"world", 44, 66, null, new ArrayList(), new HashMap()
		);
		int count = 0;
		while(generator.hasNext()) {
			SequentialValue<Object> value = generator.next();
			System.out.println(value);
			count ++;
		}
		assertTrue("the count is: " + count, count == 3*3*3);
	}
	
	public void testValueGenWithTypesrror() {
		try {
			new ExhaustiveTypedValueGenerator<Object>(
					new Class<?>[]{int.class, String.class, List.class, Float.class}, 23, "hello", new LinkedList(), "world", 44, 66
			);
			fail("Assertion error should be thrown, there is no float class");
		} catch (AssertionError e) {
			//ok here
		}
	}
	
	
	
}
